<template>
	<view class="su-form">
		<!-- form表单 -->
		<view class="uni-card uni-list su-list">
			<view class="uni-list-cell">
				<view class="uni-list-cell-navigate">
					<text class="title">旧密码</text>
					<input type="password" placeholder="请输入旧密码" v-model="passData.old_ps" />
				</view>
			</view>
			<view class="uni-list-cell">
				<view class="uni-list-cell-navigate">
					<text class="title">新密码</text>
					<input type="password" placeholder="请输入旧密码" v-model="passData.new_ps" />
				</view>
			</view>
			<view class="uni-list-cell">
				<view class="uni-list-cell-navigate">
					<text class="title">再次确认</text>
					<input type="password" placeholder="请再次输入新密码" v-model="passData.again_ps" />
				</view>
			</view>
		</view>
		<!-- 按钮 -->
		<button class="su-button pass" @click="_changePass">确定修改</button>
		<!-- 注意事项 -->
		<view class="su-careful su-flex-column">
			<text>注：</text>
			<text>1.旧密码与新密码不能一致</text>
			<text>2.密码长度6位及6位以上</text>
		</view>
		<!-- 消息提醒组件 -->
		<message ref="message"></message>
	</view>
</template>
<script>
	/**
	 * 密码修改页面
	 * */
	import md5 from "@/plugins/jssdk/md5/md5.js"
	export default {
		data() {
			return {
				passData: {}
			}
		},
		methods: {
			_changePass() {
				var {old_ps,new_ps,again_ps} = this.passData
				if (!old_ps) {
					return uni.core.message( "请输入原密码", "error")
				}
				if (!new_ps) {
					return uni.core.message( "请输入新密码", "error")
				}
				if (!again_ps) {
					return uni.core.message( "请再次输入新密码", "error")
				}
				if (new_ps != again_ps) {
					return uni.core.message( "两次密码输入不相同,请重新输入", "error")
				}
				var context = uni.core.getContext()
				var oldps = md5.hex_md5(old_ps)
				var newps = new_ps
				var param = {
					username: context['currentPersonCode'],
					password: oldps,
					new_password: newps
				}
				uni.core.post(uni.api.get("changePassword"), param,
					(data, flag, msg) => {
					if (msg.indexOf("修改成功") > -1) {
						uni.core.message( "修改密码成功")
						setTimeout(() => {
							uni.navigateBack()
						}, 1500)
					} else {
						uni.core.message( msg, "error")
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f4f4f4;
	}

	.uni-list-cell:active {
		background-color: #fff;
	}

	.su-form {
		padding-top: 70upx !important;
	}

	.su-form .su-list {
		background-color: #ffffff;
	}

	.su-button.pass {
		width: 650upx;
		height: 85upx;
		line-height: 85upx;
		margin-top: 60upx;
	}

	.su-careful {
		margin-left: auto;
		margin-right: auto;
		margin-top: 60upx;
		width: 630upx;
	}

	.su-careful text {
		font-size: 28upx;
		color: #999999;
	}
</style>
